package test.yzx.pproject.act4;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import test.yzx.pproject.R;
import test.yzx.pproject.view.CircularContractionView;


public class ViewDrawingCacheActivity extends AppCompatActivity{

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a_view_d_ca);
        final View l1 = findViewById(R.id.layout1);

        l1.postDelayed(new Runnable() {
            public void run() {
                Bitmap bmp = getViewBitmap(l1);
                l1.setVisibility(View.INVISIBLE);
                final CircularContractionView ccv = (CircularContractionView) findViewById(R.id.ccv);
                ccv.setData(bmp, new Point(100, 100), 50, Color.WHITE, 550);
                ccv.start(new Runnable() {
                    public void run() {

                        l1.postDelayed(new Runnable() {
                            public void run() {
                                ccv.reset();
                                l1.setVisibility(View.VISIBLE);
                            }
                        }, 1000);

                    }
                });
            }
        }, 2000);

    }


    private Bitmap getViewBitmap(View view){
        Bitmap bmp = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bmp);
        view.draw(canvas);
        return bmp;
    }

}
